package com.fscratch.security;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.fscratch.utils.CodecUtil;
import com.fscratch.utils.StringUtil;

//将token存储到JVM内存中
public class DefaultTokenManager implements TokenManager {

    private static Map<String, String> tokenMap = new ConcurrentHashMap<>();

    @Override
    public String createToken(String username) {
        String token = CodecUtil.createUUID();
        tokenMap.put(token, username);
        return token;
    }

    @Override
    public boolean checkToken(String token) {
        return !StringUtil.isEmpty(token) && tokenMap.containsKey(token);
    }
}